function OwnDoor( ply )
	local trace = ply:GetEyeTrace();
	
 	if( not trace.Entity:IsValid()) then
 		return;
	end
	
	if(!trace.Entity:IsDoor()) then
		return
	end
	
	if(trace.StartPos:Distance(trace.HitPos) >50) then return end
	
	if(trace.Entity:GetNWInt("OwnerID") == nil || !player.GetByID(trace.Entity:GetNWInt("OwnerID")):IsPlayer()) then
		trace.Entity:SetNWInt("OwnerID",ply:EntIndex())
		ply:ChatNotify("Owned Door")
		return
	end
	
	if(trace.Entity:GetNWInt("OwnerID") != ply:EntIndex()) then
		ply:ChatNotify("Door Already Owned")
		return	
	end
	
	if(trace.Entity:GetNWInt("OwnerID") == ply:EntIndex()) then
		trace.Entity:SetNWInt("OwnerID",0)
		trace.Entity:Fire( "unlock", "", 0 );
		ply:ChatNotify("Unowned Door")
		return
	end

end


hook.Add("ShowSpare2", "owndoor", OwnDoor) 